package cn.glutnn.controller;


import cn.glutnn.entity.Food;
import cn.glutnn.entity.Result;
import cn.glutnn.service.FoodService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 食品表(Food)表控制层
 *
 * @author msh
 * @since 2024-12-10 22:36:26
 */
@RestController
@RequestMapping("/food")
public class FoodController {
    /**
     * 服务对象
     */
    @Autowired
    private FoodService foodService;

    @GetMapping("/listFoodByBusinessId")
    public Result<List<Food>> listFoodByBusinessId(Integer businessId) {
        LambdaQueryWrapper<Food> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Food::getBusinessId, businessId);
        return Result.success(foodService.list(wrapper));
    }

    // 根据id 查询食品
    @GetMapping("/{id}")
    public Result<Food> getById(@PathVariable("id") Integer id) {
        return Result.success(foodService.getById(id));
    }

    // 更新库存
    @PutMapping("/updateStock/{foodId}")
    public Result updateStock(@PathVariable("foodId") Integer foodId,
                              @RequestParam Integer quantity) {
        foodService.updateStock(foodId, quantity);
        return Result.success("更新成功");
    }
}

